import socket
import subprocess


server = socket.socket()
server.bind(('localhost',6969))
server.listen(5)
while True:
    conn,addr = server.accept()
    print('connect: %s, addr: %s' % (conn, addr))
    while True:
        data = conn.recv(1024)
        if not data:
            continue
        # print(data.decode())
        if data.decode() == 'exit':
            print('exit ...')
            break
        status, output = subprocess.getstatusoutput(data.decode())
        send_text = output
        text_size = len(send_text.encode())
        print('text size: ', text_size)
        conn.send(str(text_size).encode())
        ack_text = conn.recv(1024).decode()
        print(ack_text)
        # print(send_text)
        conn.send(send_text.encode())


server.close()






